package neo

import org.neo4j.driver.AuthTokens
import org.neo4j.driver.GraphDatabase
import org.neo4j.driver.SessionConfig

private val databaseUri = "bolt://127.0.0.1:7687"
private val username = "admin"
private val password = "iNO^oSY#J2KXAHEf"
// 启动driver
private val driver = GraphDatabase.driver(databaseUri, AuthTokens.basic(username, password))

fun main() {
  val session = driver.session(SessionConfig.forDatabase("test"))
  // session.run("CALL db.dropDB()")
  session.run(
      "CALL db.createVertexLabel('person', 'id' , 'id' ,INT32, false, 'name' ,STRING, false)")
  session.run("CALL db.createEdgeLabel('is_friend','[[\"person\",\"person\"]]')")
  session.run("create (n1:person {name:'jack',id:1}), (n2:person {name:'lucy',id:2})")
  session.run("match (n1:person {id:1}), (n2:person {id:2}) create (n1)-[r:is_friend]->(n2)")
  val res = session.run("match (n)-[r]->(m) return n,r,m")
  res.list().forEach { record ->
    val n = record.get("n").asNode()
    println(n.asMap())
    val r = record.get("r").asRelationship()
    println(r.asMap())
    val m = record.get("m").asNode()
    println(m.asMap())
  }
}
